/**
 * @description utils api 路由
 * @author LI
 */

const router = require('koa-router')()
const { upload } = require('../../controller/utils')

router.prefix('/jihuide/utils')
const { isProd } = require('../../utils/env')

// 上传图片/视频/图纸
router.post('/upload', upload.single('file'), async (ctx, next) => {
  let up = 'uploadFiles\\'
  if (isProd) {
    up = 'uploadFiles\/'
  }
  const directory = ctx.request.file.destination.split(up)[1]
  const file = ctx.request.protocol + '://' + ctx.request.host + '/uploadFiles/' + directory + '/' + ctx.request.file.filename

  ctx.body = {
    total: 0,
    rows: file,
    success: true,
    msg: '上传成功'
  }
})

module.exports = router
